<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="__PUBLIC__/js/ajaxupload.3.6.js"></script>
<script type= "text/javascript">
    /*<![CDATA[*/
    $(document).ready(function(){
        var button		=	$('#ajax_upload_attach_button');
        var process		=	$('#ajax_upload_attach_process');
        $('#ajax_upload_attach_button').attr('disabled',false).html('上传附件').addClass('btn_b');
        new AjaxUpload(button,{
            action: '__TS__/Attach/ajax_upload/type/{$type}/uid/{$uid}',
            name: 'myfile',
            onSubmit : function(file, ext){

                this.disable();
                process.val('正在上传...');
            },
            onComplete: function(file, response){
                //alert(response);
                process.val('上传成功.');
                this.enable();

                //处理上传后的过程
                var responseData	=	eval('('+response+')');
                //alert(response);
                //alert(responseData.status);
                //上传失败
                if(responseData.status==false){
                    //弹出错误信息
                    alert(responseData.info);

                    //上传成功
                }else{
                    //执行callback
                    {$callback}(responseData.info[0]);
                }
            }
        });

    });
    /*]]>*/
</script>
<if condition="$callback eq 'attach_upload_success'">
    <script>
        //插入信息到编辑器
        function insertImageIntoEditor(imgPath,attachId){
            var frm = window.frames["Editor"];
            var frm2= frm.window.frames["HtmlEditor"].document;
            var img = "<p><img src='"+imgPath+"' onload='if(this.width>600){this.width=600}' id='attach_"+attachId+"' /></p>";
            frm2.body.innerHTML += img ;
            alert('图片插入成功！');
        }

        function deleteAttach(attach){
            $('.attach'+attach).remove();
        }
        //执行默认的callback方法
        function attach_upload_success(info){
            //判断附件类型
            //判断附件类型
            var upload_url	=	'{$Think.const.UPLOAD_URL}';				//长传目录
            var insertImage	=	'{$insert_image}';
            var imgPattern = new RegExp('^.*\.(bmp|gif|jpg|png){1}$','gi');	//图片类型匹配
            var imgPattern = new RegExp('^.*.(bmp|gif|jpg|png){1}$','gi'); //图片类型匹配
            if(imgPattern.test(info.name)){
                attachInfo = '<input class="attach'+info.id+'" type="hidden" name="attach[]" value="'+info.id+'|'+info.name+'"/>'+'<p><a class="attach'+info.id+'" href="javascript:void(0)" onclick="deleteAttach('+info.id+'<?php if($id) echo ",".$id ?>)">[删除]</a>&nbsp;<span class="attach'+info.id+'">'+info.name+'</span></p>';
            }else{
                attachInfo = '<input class="attach'+info.id+'" type="hidden" name="attach[]" value="'+info.id+'|'+info.name+'"/>'+'<p><a class="attach'+info.id+'" href= javascript:void(0) onclick="deleteAttach('+info.id+')">[删除]</a>&nbsp;<span class="attach'+info.id+'"> '+info.name+'</span></p>';
            }
            $('#attach_upload_data').append(attachInfo);
        }


    </script>
</if>
<div id="attach_upload_widget">
<div id="attach_upload_data"></div>
    <div id="attach_upload_tool">
        <input id="ajax_upload_attach_process" disabled="disabled" /> <button id="ajax_upload_attach_button" disabled="disabled">载入中</button>
		(支持以下格式：jpg,gif,png,bmp,zip,rar)
    </div>

</div>
